package cn.e3mall.sso.controller;

import cn.e3mall.common.utils.E3Result;
import cn.e3mall.sso.service.TokenService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class TokenController {

    @Autowired
    private TokenService tokenService;

    @RequestMapping("/user/token/{token}")
    @ResponseBody
    public String getUserByToken(@PathVariable String token,String callback) {
        E3Result userByToken = tokenService.getUserByToken(token);
        if(!StringUtils.isEmpty(callback)){
           return callback+"("+JSONObject.toJSONString(userByToken)+")";
        }
        return JSONObject.toJSONString(userByToken);
    }
}
